<template>
	<view>
		<view v-if='content != ""' class='content'>
			<u-parse :content="content.content"></u-parse>
		</view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				content: '',
			}
		},
		onShareAppMessage(res) {
			if (this.content != '') {
				return {
					title: this.content.title,
					desc: '广东农邻居科技',
					path: `/pages/content/detail?id=${this.content.id}`,
					imageUrl: this.content.cover
				}
			}
		},
		onLoad(options) {
			if(typeof(options.id) !== 'undefined'){
				let token = uni.getStorageSync('api_token')
				if(token == ''){
					this.request.get(`public/contents/${options.id}`).then((res) => {
						console.log(res.data)
						this.content = res.data
						uni.setNavigationBarTitle({
							title: res.data.title
						})
					})
				}else{
					this.request.get(`api/contents/${options.id}`).then((res) => {
						console.log(res.data)
						this.content = res.data
						uni.setNavigationBarTitle({
							title: res.data.title
						})
					})
				}
			}else{
				uni.showModal({
					title: '',
					content: '参数错误',
					showCancel: false,
					success: () => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
				})
			}
		},
		methods: {
			toUrl(page){
				uni.redirectTo({
					url: page
				})
			}
		}
	}
</script>

<style>
	.content{
		padding: 20px 10px;
	}
</style>